package fr.vahren.sriksal.business.impl;

import java.util.List;

import fr.vahren.sriksal.business.IMapBusiness;
import fr.vahren.sriksal.business.exception.InternalErrorException;
import fr.vahren.sriksal.controller.bean.MapTile;
import fr.vahren.sriksal.dao.IMapDao;
import fr.vahren.sriksal.dao.bean.MapDaoBean;
import fr.vahren.sriksal.dao.transform.MapTransform;

public class MapBusiness implements IMapBusiness {

	private IMapDao mapDao;

	/**
	 * @param mapDao
	 *            the mapDao to set
	 */
	public void setMapDao(IMapDao mapDao) {
		this.mapDao = mapDao;
	}

	@Override
	public long saveMap(MapTile[][] map, long userId) {
		return mapDao.saveMap(map, userId);
	}

	@Override
	public MapTile[][] getMap(long id) {
		MapDaoBean bean = mapDao.getMapByUserId(id);
		if (bean != null) {
			return MapTransform.mapDaoBeanToMapTilesArray(bean);
		} else {
			return null;
		}
	}

	@Override
	public MapTile[][] getMapByMapId(long mapId) {
		MapDaoBean bean = mapDao.getMapByMapId(mapId);
		if (bean != null) {
			return MapTransform.mapDaoBeanToMapTilesArray(bean);
		} else {
			return null;
		}
	}

	@Override
	public void addTown(long tileId) throws InternalErrorException {
		mapDao.addTown(tileId);
	}

	@Override
	public List<Long[]> getMapList(long id) {
		return mapDao.getMapList(id);
	}

	@Override
	public List<Long[]> getAvailableMapList(long userId) {
		return mapDao.getAvailableMapList(userId);
	}

}
